import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.saucedemo.com/")
input_Username = driver.find_element(by=By.ID, value="user-name")
input_Username.send_keys("standard_user")
time.sleep(1)
input_password = driver.find_element(by=By.ID, value="password")
input_password.send_keys("secret_sauce")
time.sleep(1)
submit_element = driver.find_element(by=By.ID, value="login-button")
submit_element.click()
time.sleep(1)
items = driver.find_elements(By.XPATH, '//div[@class="inventory_item"]')
for item in items:
    # print(item)
    price = item.find_element(By.CSS_SELECTOR, ".inventory_item_price").text
    price = float(price[1:])
    if price < 10:
        submit_cart = item.find_element(By.TAG_NAME, "button")
        submit_cart.click()
    time.sleep(1)

cart = driver.find_element(By.CSS_SELECTOR, '.shopping_cart_link')
cart.click()
time.sleep(1)
checkout = driver.find_element(by=By.ID, value='checkout')
checkout.click()
time.sleep(1)
inputs = driver.find_elements(By.TAG_NAME, "input")
inputs[0].send_keys("z")
time.sleep(1)
inputs[1].send_keys("l")
time.sleep(1)
inputs[2].send_keys("666")
time.sleep(1)
inputs[3].click()
time.sleep(1)
finish = driver.find_element(by=By.ID, value="finish")
finish.click()
time.sleep(10)
driver.quit()
